package com.pro.controller;

import com.pro.pojo.JsonData;
import com.pro.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * @author cyj
 * @date 2022.1.7$ 15.43$
 * @content :
 */
@RequestMapping("/system")
@Controller
public class SystemController {
    @Autowired
    private SystemService service;
    @RequestMapping("/getSystem")
    @ResponseBody
    public JsonData getSystem(HttpServletRequest request){
        //mysql版本
        Object mysql = service.getMysql();
        //服务器名称
        InetAddress localhost = null;
        try {
            localhost = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        String serverInfo = localhost.getHostName();
        //服务器地址
        String serverName = "http://" + request.getServerName();
        //端口号
        int serverPort = request.getServerPort();
        //操作系统
        Properties props = System.getProperties();
        String property = props.getProperty("os.name");
        //运行环境
        System.getProperty("java.runtime.version");
        System.getProperty("java.specification.vendor");
        System.getProperty("java.vendor.url");
        String Environment = System.getProperty("java.runtime.version")+"," + System.getProperty("java.specification.vendor")+","+ System.getProperty("java.vendor.url");
        List<Object> list = new ArrayList<>();
        list.add(mysql);
        list.add(serverName);
        list.add(serverInfo);
        list.add(serverPort);
        list.add(property);
        list.add(Environment);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务端错误");
    }
}
